package com.lvwenguo.controller.input;

import com.google.gson.Gson;
import com.lvwenguo.model.CategoryPurchaseList;
import com.lvwenguo.service.PurchaseServiceInter;
import com.lvwenguo.service.serviceImple.PurchaseServiceImple;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//用于商品录入异步交互，可扩展
@WebServlet(urlPatterns = "/ProductOntServlet")
public class ProductOntServlet extends HttpServlet {
    PurchaseServiceInter purchaseServiceImpol =new PurchaseServiceImple();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String bar_code = req.getParameter("bar_code");
        CategoryPurchaseList categoryPurchaseList = purchaseServiceImpol.selectYibu(bar_code);
        try {
            Gson gson=new Gson();
            //将对象转换为json数据
            String categoryPurchaseListJson = gson.toJson(categoryPurchaseList);
            resp.getWriter().print(categoryPurchaseListJson);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}
